package com.itheima.tanhua.vo.mongo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.itheima.tanhua.pojo.db.BasePojo;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * @author 芝士雪豹
 * @create 2022/9/19/17:43
 */

@Data
public class UserInfoVo extends BasePojo implements Serializable {
    @TableId(type = IdType.INPUT)
    private Long id;
    private String gender;
    private String nickname;
    private String birthday;
    private String city;
    private String avatar;
    private String tags;
    private String education;

    private String income;
    private Integer marriage;
    @TableField(exist = false)
    private String age;

    public String getAge(){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate birthday = LocalDate.parse(this.birthday, formatter);
        //以年为单位,从输入的日期 到现在 的年数
        Long between = ChronoUnit.YEARS.between(birthday, LocalDate.now());
        return between.toString();
    }
}
